// eslint-disable-next-line @typescript-eslint/prefer-namespace-keyword, @typescript-eslint/no-namespace
export module LogUtil {
  // const filterLevel: string = '';
  const printTrace = false;

  export function d(tag: string, ...message: unknown[]) {
    console.debug(`[${tag}]`, ...message);
    if (printTrace) {
      console.trace();
    }
  }

  export function i(tag: string, ...message: unknown[]) {
    console.log(`[${tag}]`, ...message);
    if (printTrace) {
      console.trace();
    }
  }

  export function io(tag: string, ...message: unknown[]) {
    const temp = message.map((element) => {
      if (typeof element === 'object') {
        return JSON.parse(JSON.stringify(element, null, 2));
      } else {
        return element;
      }
    });
    console.log(`[${tag}]`, ...temp);
    if (printTrace) {
      console.trace();
    }
  }

  export function w(tag: string, ...message: unknown[]) {
    console.warn(`[${tag}]`, ...message);
    if (this.printTrace) {
      console.trace();
    }
  }

  export function e(tag: string, ...message: unknown[]) {
    console.error(`[${tag}]`, ...message);
    message.forEach((element) => {
      if (element instanceof Error) {
        console.error(element);
      }
    });
  }
}
